home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Bank smakow / BankSmakow.air / BankSmakow.swf / scripts / mx / managers / LayoutManager.as < prev    next >
Text File  |  2009-12-16  |  15KB  |  438 lines

  1. package mx.managers
  2. {
  3.    import flash.display.Stage;
  4.    import flash.events.Event;
  5.    import flash.events.EventDispatcher;
  6.    import mx.core.ApplicationGlobals;
  7.    import mx.core.UIComponent;
  8.    import mx.core.mx_internal;
  9.    import mx.events.FlexEvent;
  10.    import mx.managers.layoutClasses.PriorityQueue;
  11.    
  12.    use namespace mx_internal;
  13.    
  14.    public class LayoutManager extends EventDispatcher implements ILayoutManager
  15.    {
  16.       
  17.       mx_internal static const VERSION:String = "3.5.0.12683";
  18.       
  19.       private static var instance:LayoutManager;
  20.        
  21.       
  22.       private var invalidateClientPropertiesFlag:Boolean = false;
  23.       
  24.       private var invalidateDisplayListQueue:PriorityQueue;
  25.       
  26.       private var updateCompleteQueue:PriorityQueue;
  27.       
  28.       private var invalidateDisplayListFlag:Boolean = false;
  29.       
  30.       private var invalidateClientSizeFlag:Boolean = false;
  31.       
  32.       private var invalidateSizeQueue:PriorityQueue;
  33.       
  34.       private var originalFrameRate:Number;
  35.       
  36.       private var invalidatePropertiesFlag:Boolean = false;
  37.       
  38.       private var invalidatePropertiesQueue:PriorityQueue;
  39.       
  40.       private var invalidateSizeFlag:Boolean = false;
  41.       
  42.       private var callLaterPending:Boolean = false;
  43.       
  44.       private var _usePhasedInstantiation:Boolean = false;
  45.       
  46.       private var callLaterObject:UIComponent;
  47.       
  48.       private var targetLevel:int = 2.147483647E9;
  49.       
  50.       public function LayoutManager()
  51.       {
  52.          updateCompleteQueue = new PriorityQueue();
  53.          invalidatePropertiesQueue = new PriorityQueue();
  54.          invalidateSizeQueue = new PriorityQueue();
  55.          invalidateDisplayListQueue = new PriorityQueue();
  56.          super();
  57.       }
  58.       
  59.       public static function getInstance() : LayoutManager
  60.       {
  61.          if(!instance)
  62.          {
  63.             instance = new LayoutManager();
  64.          }
  65.          return instance;
  66.       }
  67.       
  68.       public function set usePhasedInstantiation(param1:Boolean) : void
  69.       {
  70.          var sm:ISystemManager = null;
  71.          var stage:Stage = null;
  72.          var value:Boolean = param1;
  73.          if(_usePhasedInstantiation != value)
  74.          {
  75.             _usePhasedInstantiation = value;
  76.             try
  77.             {
  78.                sm = SystemManagerGlobals.topLevelSystemManagers[0];
  79.                stage = SystemManagerGlobals.topLevelSystemManagers[0].stage;
  80.                if(stage)
  81.                {
  82.                   if(value)
  83.                   {
  84.                      originalFrameRate = stage.frameRate;
  85.                      stage.frameRate = 1000;
  86.                   }
  87.                   else
  88.                   {
  89.                      stage.frameRate = originalFrameRate;
  90.                   }
  91.                }
  92.             }
  93.             catch(e:SecurityError)
  94.             {
  95.             }
  96.          }
  97.       }
  98.       
  99.       private function waitAFrame() : void
  100.       {
  101.          callLaterObject.callLater(doPhasedInstantiation);
  102.       }
  103.       
  104.       public function validateClient(param1:ILayoutManagerClient, param2:Boolean = false) : void
  105.       {
  106.          var _loc3_:ILayoutManagerClient = null;
  107.          var _loc4_:int = 0;
  108.          var _loc5_:Boolean = false;
  109.          var _loc6_:int = targetLevel;
  110.          if(targetLevel == int.MAX_VALUE)
  111.          {
  112.             targetLevel = param1.nestLevel;
  113.          }
  114.          while(!_loc5_)
  115.          {
  116.             _loc5_ = true;
  117.             _loc3_ = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallestChild(param1));
  118.             while(_loc3_)
  119.             {
  120.                _loc3_.validateProperties();
  121.                if(!_loc3_.updateCompletePendingFlag)
  122.                {
  123.                   updateCompleteQueue.addObject(_loc3_,_loc3_.nestLevel);
  124.                   _loc3_.updateCompletePendingFlag = true;
  125.                }
  126.                _loc3_ = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallestChild(param1));
  127.             }
  128.             if(invalidatePropertiesQueue.isEmpty())
  129.             {
  130.                invalidatePropertiesFlag = false;
  131.                invalidateClientPropertiesFlag = false;
  132.             }
  133.             _loc3_ = ILayoutManagerClient(invalidateSizeQueue.removeLargestChild(param1));
  134.             while(_loc3_)
  135.             {
  136.                _loc3_.validateSize();
  137.                if(!_loc3_.updateCompletePendingFlag)
  138.                {
  139.                   updateCompleteQueue.addObject(_loc3_,_loc3_.nestLevel);
  140.                   _loc3_.updateCompletePendingFlag = true;
  141.                }
  142.                if(invalidateClientPropertiesFlag)
  143.                {
  144.                   _loc3_ = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallestChild(param1));
  145.                   if(_loc3_)
  146.                   {
  147.                      invalidatePropertiesQueue.addObject(_loc3_,_loc3_.nestLevel);
  148.                      _loc5_ = false;
  149.                      break;
  150.                   }
  151.                }
  152.                _loc3_ = ILayoutManagerClient(invalidateSizeQueue.removeLargestChild(param1));
  153.             }
  154.             if(invalidateSizeQueue.isEmpty())
  155.             {
  156.                invalidateSizeFlag = false;
  157.                invalidateClientSizeFlag = false;
  158.             }
  159.             if(!param2)
  160.             {
  161.                _loc3_ = ILayoutManagerClient(invalidateDisplayListQueue.removeSmallestChild(param1));
  162.                while(_loc3_)
  163.                {
  164.                   _loc3_.validateDisplayList();
  165.                   if(!_loc3_.updateCompletePendingFlag)
  166.                   {
  167.                      updateCompleteQueue.addObject(_loc3_,_loc3_.nestLevel);
  168.                      _loc3_.updateCompletePendingFlag = true;
  169.                   }
  170.                   if(invalidateClientPropertiesFlag)
  171.                   {
  172.                      _loc3_ = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallestChild(param1));
  173.                      if(_loc3_)
  174.                      {
  175.                         invalidatePropertiesQueue.addObject(_loc3_,_loc3_.nestLevel);
  176.                         _loc5_ = false;
  177.                         break;
  178.                      }
  179.                   }
  180.                   if(invalidateClientSizeFlag)
  181.                   {
  182.                      _loc3_ = ILayoutManagerClient(invalidateSizeQueue.removeLargestChild(param1));
  183.                      if(_loc3_)
  184.                      {
  185.                         invalidateSizeQueue.addObject(_loc3_,_loc3_.nestLevel);
  186.                         _loc5_ = false;
  187.                         break;
  188.                      }
  189.                   }
  190.                   _loc3_ = ILayoutManagerClient(invalidateDisplayListQueue.removeSmallestChild(param1));
  191.                }
  192.                if(invalidateDisplayListQueue.isEmpty())
  193.                {
  194.                   invalidateDisplayListFlag = false;
  195.                }
  196.             }
  197.          }
  198.          if(_loc6_ == int.MAX_VALUE)
  199.          {
  200.             targetLevel = int.MAX_VALUE;
  201.             if(!param2)
  202.             {
  203.                _loc3_ = ILayoutManagerClient(updateCompleteQueue.removeLargestChild(param1));
  204.                while(_loc3_)
  205.                {
  206.                   if(!_loc3_.initialized)
  207.                   {
  208.                      _loc3_.initialized = true;
  209.                   }
  210.                   _loc3_.dispatchEvent(new FlexEvent(FlexEvent.UPDATE_COMPLETE));
  211.                   _loc3_.updateCompletePendingFlag = false;
  212.                   _loc3_ = ILayoutManagerClient(updateCompleteQueue.removeLargestChild(param1));
  213.                }
  214.             }
  215.          }
  216.       }
  217.       
  218.       private function validateProperties() : void
  219.       {
  220.          var _loc1_:ILayoutManagerClient = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallest());
  221.          while(_loc1_)
  222.          {
  223.             _loc1_.validateProperties();
  224.             if(!_loc1_.updateCompletePendingFlag)
  225.             {
  226.                updateCompleteQueue.addObject(_loc1_,_loc1_.nestLevel);
  227.                _loc1_.updateCompletePendingFlag = true;
  228.             }
  229.             _loc1_ = ILayoutManagerClient(invalidatePropertiesQueue.removeSmallest());
  230.          }
  231.          if(invalidatePropertiesQueue.isEmpty())
  232.          {
  233.             invalidatePropertiesFlag = false;
  234.          }
  235.       }
  236.       
  237.       public function invalidateProperties(param1:ILayoutManagerClient) : void
  238.       {
  239.          if(!invalidatePropertiesFlag && ApplicationGlobals.application.systemManager)
  240.          {
  241.             invalidatePropertiesFlag = true;
  242.             if(!callLaterPending)
  243.             {
  244.                if(!callLaterObject)
  245.                {
  246.                   callLaterObject = new UIComponent();
  247.                   callLaterObject.systemManager = ApplicationGlobals.application.systemManager;
  248.                   callLaterObject.callLater(waitAFrame);
  249.                }
  250.                else
  251.                {
  252.                   callLaterObject.callLater(doPhasedInstantiation);
  253.                }
  254.                callLaterPending = true;
  255.             }
  256.          }
  257.          if(targetLevel <= param1.nestLevel)
  258.          {
  259.             invalidateClientPropertiesFlag = true;
  260.          }
  261.          invalidatePropertiesQueue.addObject(param1,param1.nestLevel);
  262.       }
  263.       
  264.       public function invalidateDisplayList(param1:ILayoutManagerClient) : void
  265.       {
  266.          if(!invalidateDisplayListFlag && ApplicationGlobals.application.systemManager)
  267.          {
  268.             invalidateDisplayListFlag = true;
  269.             if(!callLaterPending)
  270.             {
  271.                if(!callLaterObject)
  272.                {
  273.                   callLaterObject = new UIComponent();
  274.                   callLaterObject.systemManager = ApplicationGlobals.application.systemManager;
  275.                   callLaterObject.callLater(waitAFrame);
  276.                }
  277.                else
  278.                {
  279.                   callLaterObject.callLater(doPhasedInstantiation);
  280.                }
  281.                callLaterPending = true;
  282.             }
  283.          }
  284.          else if(!invalidateDisplayListFlag && !ApplicationGlobals.application.systemManager)
  285.          {
  286.          }
  287.          invalidateDisplayListQueue.addObject(param1,param1.nestLevel);
  288.       }
  289.       
  290.       private function validateDisplayList() : void
  291.       {
  292.          var _loc1_:ILayoutManagerClient = ILayoutManagerClient(invalidateDisplayListQueue.removeSmallest());
  293.          while(_loc1_)
  294.          {
  295.             _loc1_.validateDisplayList();
  296.             if(!_loc1_.updateCompletePendingFlag)
  297.             {
  298.                updateCompleteQueue.addObject(_loc1_,_loc1_.nestLevel);
  299.                _loc1_.updateCompletePendingFlag = true;
  300.             }
  301.             _loc1_ = ILayoutManagerClient(invalidateDisplayListQueue.removeSmallest());
  302.          }
  303.          if(invalidateDisplayListQueue.isEmpty())
  304.          {
  305.             invalidateDisplayListFlag = false;
  306.          }
  307.       }
  308.       
  309.       public function validateNow() : void
  310.       {
  311.          var _loc1_:int = 0;
  312.          if(!usePhasedInstantiation)
  313.          {
  314.             _loc1_ = 0;
  315.             while(callLaterPending && _loc1_++ < 100)
  316.             {
  317.                doPhasedInstantiation();
  318.             }
  319.          }
  320.       }
  321.       
  322.       private function validateSize() : void
  323.       {
  324.          var _loc1_:ILayoutManagerClient = ILayoutManagerClient(invalidateSizeQueue.removeLargest());
  325.          while(_loc1_)
  326.          {
  327.             _loc1_.validateSize();
  328.             if(!_loc1_.updateCompletePendingFlag)
  329.             {
  330.                updateCompleteQueue.addObject(_loc1_,_loc1_.nestLevel);
  331.                _loc1_.updateCompletePendingFlag = true;
  332.             }
  333.             _loc1_ = ILayoutManagerClient(invalidateSizeQueue.removeLargest());
  334.          }
  335.          if(invalidateSizeQueue.isEmpty())
  336.          {
  337.             invalidateSizeFlag = false;
  338.          }
  339.       }
  340.       
  341.       private function doPhasedInstantiation() : void
  342.       {
  343.          var _loc1_:ILayoutManagerClient = null;
  344.          if(usePhasedInstantiation)
  345.          {
  346.             if(invalidatePropertiesFlag)
  347.             {
  348.                validateProperties();
  349.                ApplicationGlobals.application.dispatchEvent(new Event("validatePropertiesComplete"));
  350.             }
  351.             else if(invalidateSizeFlag)
  352.             {
  353.                validateSize();
  354.                ApplicationGlobals.application.dispatchEvent(new Event("validateSizeComplete"));
  355.             }
  356.             else if(invalidateDisplayListFlag)
  357.             {
  358.                validateDisplayList();
  359.                ApplicationGlobals.application.dispatchEvent(new Event("validateDisplayListComplete"));
  360.             }
  361.          }
  362.          else
  363.          {
  364.             if(invalidatePropertiesFlag)
  365.             {
  366.                validateProperties();
  367.             }
  368.             if(invalidateSizeFlag)
  369.             {
  370.                validateSize();
  371.             }
  372.             if(invalidateDisplayListFlag)
  373.             {
  374.                validateDisplayList();
  375.             }
  376.          }
  377.          if(invalidatePropertiesFlag || invalidateSizeFlag || invalidateDisplayListFlag)
  378.          {
  379.             callLaterObject.callLater(doPhasedInstantiation);
  380.          }
  381.          else
  382.          {
  383.             usePhasedInstantiation = false;
  384.             callLaterPending = false;
  385.             _loc1_ = ILayoutManagerClient(updateCompleteQueue.removeLargest());
  386.             while(_loc1_)
  387.             {
  388.                if(!_loc1_.initialized && _loc1_.processedDescriptors)
  389.                {
  390.                   _loc1_.initialized = true;
  391.                }
  392.                _loc1_.dispatchEvent(new FlexEvent(FlexEvent.UPDATE_COMPLETE));
  393.                _loc1_.updateCompletePendingFlag = false;
  394.                _loc1_ = ILayoutManagerClient(updateCompleteQueue.removeLargest());
  395.             }
  396.             dispatchEvent(new FlexEvent(FlexEvent.UPDATE_COMPLETE));
  397.          }
  398.       }
  399.       
  400.       public function isInvalid() : Boolean
  401.       {
  402.          return invalidatePropertiesFlag || invalidateSizeFlag || invalidateDisplayListFlag;
  403.       }
  404.       
  405.       public function get usePhasedInstantiation() : Boolean
  406.       {
  407.          return _usePhasedInstantiation;
  408.       }
  409.       
  410.       public function invalidateSize(param1:ILayoutManagerClient) : void
  411.       {
  412.          if(!invalidateSizeFlag && ApplicationGlobals.application.systemManager)
  413.          {
  414.             invalidateSizeFlag = true;
  415.             if(!callLaterPending)
  416.             {
  417.                if(!callLaterObject)
  418.                {
  419.                   callLaterObject = new UIComponent();
  420.                   callLaterObject.systemManager = ApplicationGlobals.application.systemManager;
  421.                   callLaterObject.callLater(waitAFrame);
  422.                }
  423.                else
  424.                {
  425.                   callLaterObject.callLater(doPhasedInstantiation);
  426.                }
  427.                callLaterPending = true;
  428.             }
  429.          }
  430.          if(targetLevel <= param1.nestLevel)
  431.          {
  432.             invalidateClientSizeFlag = true;
  433.          }
  434.          invalidateSizeQueue.addObject(param1,param1.nestLevel);
  435.       }
  436.    }
  437. }
  438.